<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;

class CommonFormResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id'=>$this->id,
            'title'=>$this->title,
            'content'=>$this->content,
            'type'=>$this->type,
            'username'=>optional($this->staff)->username ?? '-',
            'type_name'=>$this->type_name,
            'files'=>FilesResource::collection($this->files),
            'created_at'=>Carbon::parse($this->created_at)->toDateTimeString(),
        ];
    }
}
